<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/12/22 13:09:51 $)
// $RCSfile: setup.php,v $ : $Revision: 1.2 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Called when the module is to be installed
*/
function _downloads_install($action, $page = '') {
	global $_SWIFT, $__LANG;

	if ($action == "getpages")
	{
		return "1";
	} else if ($action == "buildpage") {
		$_SWIFT["query"]["create"]["downloadcategories"] = "CREATE TABLE ". TABLE_PREFIX ."downloadcategories (
																				downloadcategoryid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				parentcategoryid INT UNSIGNED NOT NULL DEFAULT '0',
																				staffid INT UNSIGNED NOT NULL DEFAULT '0',
																				title VARCHAR(255) NOT NULL DEFAULT '',
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				totalitems INT UNSIGNED NOT NULL DEFAULT '0',
																				categorytype VARCHAR(20) NOT NULL DEFAULT 'public',
																				displayorder INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (downloadcategoryid),
																				KEY downloadcategories1 (parentcategoryid)
																			);";

		$_SWIFT["query"]["create"]["downloaditems"] = "CREATE TABLE ". TABLE_PREFIX ."downloaditems (
																				downloaditemid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				downloadcategoryid INT UNSIGNED NOT NULL DEFAULT '0',
																				downloadmaskid VARCHAR(100) NOT NULL DEFAULT '',
																				title VARCHAR(255) NOT NULL DEFAULT '',
																				version VARCHAR(50) NOT NULL DEFAULT '',
																				filelink VARCHAR(255) NOT NULL DEFAULT '',
																				filename VARCHAR(255) NOT NULL DEFAULT '',
																				storedfilename VARCHAR(255) NOT NULL DEFAULT '',
																				filesize INT UNSIGNED NOT NULL DEFAULT '0',
																				filetype VARCHAR(150) NOT NULL DEFAULT '',
																				totaldownloads INT UNSIGNED NOT NULL DEFAULT '0',
																				displayorder INT UNSIGNED NOT NULL DEFAULT '0',
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				updatedateline INT UNSIGNED NOT NULL DEFAULT '0',
																				itempassword VARCHAR(50) NOT NULL DEFAULT '',
																				totalcomments INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (downloaditemid),
																				KEY downloaditems1 (downloadcategoryid),
																				KEY downloaditems2 (downloadmaskid)
																			);";

		$_SWIFT["query"]["create"]["downloaddesc"] = "CREATE TABLE ". TABLE_PREFIX ."downloaddesc (
																				downloaddescid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				downloaditemid INT UNSIGNED NOT NULL DEFAULT '0',
																				description MEDIUMTEXT,
																				PRIMARY KEY (downloaddescid),
																				KEY downloaddesc1 (downloaditemid)
																			);";

	
		$_SWIFT["query"]["insert"]["settings"][0] = "INSERT INTO `". TABLE_PREFIX ."settings`(`section`, `vkey`, `data`) VALUES('registeredmodules', '". MODULE_DOWNLOADS ."', '1')";
	}
}

/**
* Uninstall Routine
*/
function _downloads_uninstall()
{
	global $_SWIFT;

	$_SWIFT["query"]["drop"]["downloadcategories"] = "DROP TABLE `". TABLE_PREFIX ."downloadcategories`;";

	$_SWIFT["query"]["drop"]["downloaditems"] = "DROP TABLE `". TABLE_PREFIX ."downloaditems`;";

	$_SWIFT["query"]["drop"]["downloaddesc"] = "DROP TABLE `". TABLE_PREFIX ."downloaddesc`;";

	$_SWIFT["query"]["delete"]["settings"][0] = "DELETE FROM `". TABLE_PREFIX ."settings` WHERE `section` = 'registeredmodules' AND `vkey` = '". MODULE_DOWNLOADS ."';";
}
?>